<?php

class Test_Abovo_Model_Company extends Solar_Test {

    private $_companies;
    
    public function __construct($config = array())
    {
        parent::__construct($config);
        $this->_companies = Solar::factory('Abovo_Model_Company');
    }
    
    public function __destruct()
    {
        //$this->_companies->delete();
    }
    
    public function testSave()
    {
        $data = array(
            'name'         => 'Example Company',
            'short'        => 'Example',
            'descr'        => 'A description of the company',
            'country'      => 'FI',
            'adr'          => 'Something 1234 PO 123',
            'city'         => 'Espoo',
            'vat'          => 'FI12345678',
            'postal_code'  => '02160',
            'handle' => 'antti',
        );
        
        for ($i = 0; $i<10; $i++) {
            $this->assertTrue((bool) $this->_companies->save($data));
        }
        
        $data['city']    = 'Helsinki';
        $data['country'] = 'US';
        for ($i = 0; $i<10; $i++) {
            $this->assertTrue((bool) $this->_companies->save($data));
        }
    }
    
    public function testFind()
    {
        $this->skip();
        $s = array(
            'name' => 'xampl',
        );
        $this->assertSame(count($this->_companies->find($s, 200)), 20);

        $s = array(
            'name'    => 'xampl',
            'country' => 'FI',
        );
        $this->assertSame(count($this->_companies->find($s, 200)), 10);
        
    }
    
    public function testFetchCitys()
    {
        $citys = array(
            'Espoo'    => '10',
            'Helsinki' => '10',
            'Vaasa'    => '1',
        );
        $this->assertSame($this->_companies->fetchCitys(), $citys);
    }
}
